/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__split_iprange_portrange.c                       */
/*  NOTE      =                                                    */
/*  DATE      = 2014/12/12 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>
#include <protobuf-c/protobuf-c.h>

#include "../../comm/frcmd_parse_detail.h"
#include "../../comm/client.pb-c.h"
#include "../../comm/frcmd_parse.h"
#include "../../comm/apm.pb-c.h"
#include "../../comm/frcmd_client.h"
#include "../../comm/frcomm.h"
#include "../../comm/frmem.h"
#include "../../comm/frsutl.h"
#include "../../comm/apmtest_cunit.h"

static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

void __split_iprange_portrange(char *p_iprange, char **pp_portrange);

void case1(void)
{
    char *p_iprange = NULL;
    char *p_portrange = NULL;

    p_iprange = frmalloc(strlen("192.168.1.0|22") + 1);
    snprintf(p_iprange,strlen("192.168.1.0|22") + 1,"%s","192.168.1.0|22");

    __split_iprange_portrange(p_iprange,&p_portrange);

    CU_ASSERT_STRING_EQUAL(p_iprange,"192.168.1.0");
    CU_ASSERT_STRING_EQUAL(p_portrange,"22");

    frfree(p_iprange);

}

void case2(void)
{
    int i_ret = 0;
    char *p_iprange = NULL;
    char *p_portrange = NULL;

    p_iprange = frmalloc(strlen("192.168.1.1-192.168.1.5|80-100") + 1);
    snprintf(p_iprange,strlen("192.168.1.1-192.168.1.5|80-100") + 1,"%s","192.168.1.1-192.168.1.5|80-100");

    __split_iprange_portrange(p_iprange,&p_portrange);

    CU_ASSERT_STRING_EQUAL(p_iprange,"192.168.1.1-192.168.1.5");
    CU_ASSERT_STRING_EQUAL(p_portrange,"80-100");

    frfree(p_iprange);

}

int add_suite()
{
	CU_pSuite pSuite = NULL;

	pSuite = CU_add_suite("t__split_iprange_portrange 测试", __suite_init, __suite_cleanup);

	if (NULL == pSuite)
	{
		return 1;
	}


    //增加测试用例
   	CU_add_test(pSuite, "case1", case1);

   	CU_add_test(pSuite, "case2", case2);

    return 0;

}

int main(int argc, char **argv)
{
    frmem_init();
    run_cunit(add_suite);
    frshow_leak();
    frmem_destroy();
    return 0;
}